﻿@model Subfaculty.ViewModels.AllocationListViewModel
@using Entities;
@using Subfaculty.Helpers;
<script type="text/javascript">
    $(document).ready(onDocumentReady);
    function onDocumentReady() {
        $("#curentDepartment").change(onChangeDirection);
        $("#btn_create")
            .button()
            .click(function () {
                window.location = '@Url.Action("/Create/")' + '@Model.curentDepartment.ToString()';
            });
    }
    function onChangeDirection() {
        window.location = '@Url.Action("/Index/")' + $("#curentDepartment").val();
    }
</script>
<div id="subMenu">
    <span>Кафедра: @Html.DropDownList("curentDepartment")
    </span><span id="btnCreate">
        <button type="button" id="btn_create">
            Создать новый элемент</button>
    </span>
</div>
<hr />
<table align="center" class="smallTable">
@{
                IList<String> titleList = new List<String>();
                titleList.Add("Дисциплина"); titleList.Add("Группы"); titleList.Add("Подгруппы, шт."); titleList.Add("Семестр");
                titleList.Add("Форма ОргСРС"); titleList.Add("Ауд. по плану"); titleList.Add("Сам. по плану"); titleList.Add("Л в сем.");
                titleList.Add("П по плану"); titleList.Add("П всего"); titleList.Add("Лаб по плану"); titleList.Add("Лаб всего");
                titleList.Add("Конс."); titleList.Add("Предэкз.конс."); 
}
    @Html.DisplayTitleForTable(titleList)
    
    @foreach (var item in Model.Allocations)
    {
		try
		{


        StudyPlanItem SP = item.StudyPlanItems.First();        
        <tr>
            <td>@(SP.Discipline.DisciplineTitle)
            </td>
            @{
				
            int GroupCount = item.LoadAtoms.First(x => x.LoadType == "Лекции").Groups.Count();
            String groupList = "";
            foreach (Group group in item.LoadAtoms.First(x => x.LoadType == "Лекции").Groups)
            {
                groupList += group.GroupTitle + ", ";
            }
            groupList = groupList.Remove(groupList.Length - 2, 2);        
            }
            <td>@(groupList)
            </td>
            @{
                //int labsCount = item.LoadAtoms.Count(x => x.LoadType == "Лабораторные");
                //int subGroupCount = GroupCount * (GroupCount / labsCount);
                int subGroupCount = 3;
            }
            <td>@(subGroupCount)
            </td>
            <td>@(SP.Semestr)
            </td>
            <td>@(SP.TypeSRS)
            </td>
            <td>@(SP.HoursLaboratory + SP.HoursLecture + SP.HoursPractice)
            </td>
            <td>@(SP.HoursSRS)
            </td>
            <td>@(SP.HoursLecture)
            </td>
            <td>@(SP.HoursPractice)
            </td>
            <td>@(SP.HoursPractice * GroupCount)
            </td>
            <td>@(SP.HoursLaboratory)
            </td>
            <td>@(SP.HoursLaboratory * subGroupCount)
            </td>
            <td>@(GroupCount * SP.HoursLecture * item.FactorForConsultation)
            </td>
            <td>@(GroupCount * item.FactorForBeforeExam)
            </td>
            <td>
                <div align="center">
                    <a href="@Url.Action("/Delete/") + @item.Id.ToString()">
                        <img src="../../../Content/icons/delete.png" alt="Удалить" />
                    </a>
                </div>
            </td>
        </tr>
				}
		catch (Exception)
		{
			

		}
	}
</table>
